using dotnet_ef_admin.Src.Models;

namespace dotnet_ef_admin.Src.Services;

/// <summary>
/// 菜单服务接口，定义了菜单相关的操作方法。
/// </summary>
public interface IMenuService {
    /// <summary>
    /// 异步获取所有菜单。
    /// </summary>
    /// <returns>返回一个包含所有菜单的集合。</returns>
    Task<IEnumerable<MenuNode>> GetAllMenusAsync(FindAllDictTypesDto dto);

    /// <summary>
    /// 异步根据ID获取菜单。
    /// </summary>
    /// <param name="id">菜单ID。</param>
    /// <returns>返回与ID匹配的菜单，如果没有找到则返回null。</returns>
    Task<MenuNodeResult?> GetMenuByIdAsync(int id);

    /// <summary>
    /// 异步创建新菜单。
    /// </summary>
    /// <param name="menu">要创建的菜单对象。</param>
    /// <returns>返回创建的菜单。</returns>
    Task<MenuNodeResult> CreateMenuAsync(MneuNodeRequest menu);

    /// <summary>
    /// 异步更新现有菜单。
    /// </summary>
    /// <param name="menu">要更新的菜单对象。</param>
    /// <returns>返回更新后的菜单。</returns>
    Task<MenuNodeResult> UpdateMenuAsync(MenuNodeResult menu);

    /// <summary>
    /// 异步删除菜单。
    /// </summary>
    /// <param name="id">要删除的菜单ID。</param>
    Task DeleteMenuAsync(int id);

    Task<List<MenuRoute>> GetListRoutes();
}

public class FindAllDictTypesDto {
    public string Keywords { get; set; } = "";
    public int? PageNum { get; set; } = 1;
    public int? PageSize { get; set; } = 10;
}

public class MenuNode {
    /// <summary>
    ///     父菜单ID
    /// </summary>
    public int ParentId { get; set; } = 0;

    /// <summary>
    ///     菜单名称
    /// </summary>
    public string Name { get; set; } = string.Empty;

    /// <summary>
    ///     菜单类型
    /// </summary>
    public string Type { get; set; } = string.Empty;

    /// <summary>
    ///     路由名称
    /// </summary>
    public string RouteName { get; set; } = string.Empty;

    /// <summary>
    ///     路由路径
    /// </summary>
    public string RoutePath { get; set; } = string.Empty;

    /// <summary>
    ///     组件名称
    /// </summary>
    public string Component { get; set; } = string.Empty;

    /// <summary>
    ///     排序值
    /// </summary>
    public int Sort { get; set; } = 0;

    /// <summary>
    ///     是否可见
    /// </summary>
    public int Visible { get; set; } = 0;

    /// <summary>
    ///     图标
    /// </summary>
    public string Icon { get; set; } = string.Empty;

    /// <summary>
    ///     重定向路径
    /// </summary>
    public string Redirect { get; set; } = string.Empty;

    /// <summary>
    ///     权限
    /// </summary>
    public string Perm { get; set; } = string.Empty;

    /// <summary>
    ///     子菜单
    /// </summary>
    public List<MenuNode> Children { get; set; } = [];

    public int KeepAlive { get; set; } = 1;
}

public class MneuNodeRequest : MenuNode {
}

public class MenuNodeResult : MenuNode {
    /// <summary>
    ///     菜单ID
    /// </summary>
    public int Id { get; set; } = 0;
}


public class MenuRoute {
    public string Component { get; set; } = string.Empty;
    public string Name { get; set; } = string.Empty;
    public string Path { get; set; } = string.Empty;
    public string Redirect { get; set; } = string.Empty;
    public List<MenuRoute> Children { get; set; } = [];
    public MenuMeta Meta { get; set; } = new MenuMeta();
}

public class MenuMeta {
    public string Title { get; set; } = string.Empty;
    public string Icon { get; set; } = string.Empty;
    public bool Hidden { get; set; } = false;
    public bool KeepAlive { get; set; } = false;
    public bool AlwaysShow { get; set; } = false;
    // public List<string> Roles { get; set; } = [];
}